from rest_framework import serializers
from rest_framework.views import APIView
from rest_framework.response import Response

from app01 import models
from rest_framework.pagination import PageNumberPagination


class UserModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.UserInfo
        fields = ["id","username","age","email"]

class MyPageNumberPagination(PageNumberPagination):
    page_size_query_param = "size"
    page_size = 2
    max_page_size = 100


class UserView(APIView):
    def get(self,request,*args,**kwargs):
        queryset = models.UserInfo.objects.all().order_by("id")

        pager = MyPageNumberPagination()
        paginate_queryset = pager.paginate_queryset(queryset,request,self)

        ser = UserModelSerializer(instance=paginate_queryset,many=True)

        return Response(ser.data)



